<?php
/**
 * Created by PhpStorm.
 * User: HS032
 * Date: 2020/8/21
 * Time: 13:52
 */

namespace ticket\modules\backend\controllers;


use ticket\libs\Tools;
use ticket\modules\backend\models\CommonApp;
use Yii;

/*** 实例控制器
 * Class InstanceController
 * @package ticket\modules\backend\controllers
 */
class InstanceController extends BasicController
{

    /*** 实例列表
     * @return false|string
     */
    public function actionInstanceList()
    {

        $get = Yii::$app->request->get();
        $page = isset($get['page'])?(int)$get['page']:1;

        $pageSize = Yii::$app->params['pageSize'];
        if ($pageSize == ''){
            $pageSize = 10;
        }
        $appModel = new CommonApp();
//        $list = $appModel::find()->offset($pageSize * ($page - 1))->orderBy(['app_id' => SORT_DESC])->asArray()->all();

        if($this->userInfo['issuper'] == 1){
            $list = $appModel::find()
                ->where('comid = :comid', [':comid' => $this->userInfo['comid']])
                ->orderBy(['app_id' => SORT_DESC])->asArray()->all();
        }else{
            $list = $appModel::find()
                ->where('comid = :comid', [':comid' => $this->userInfo['comid']])
                ->andWhere([
                    'in', 'appid', $this->permissionApps
                ])
                ->orderBy(['app_id' => SORT_DESC])->asArray()->all();
        }

        return Tools::showRes(0,'success',[
            'instanceList' => $list,
        ]);

    }
    
    
    
    
}